/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-10-06 21:08:50
 * Last Modified: 2016-08-30 14:15:57
 * File Name: controllers/auto.go
 * Description:
 */
package controllers

import (
	"passport/auth"
	"passport/errorcode"
	"passport/login"
)

type AutoLoginController struct {
	LoginedController
}

/*
	自动登录
*/
func (p *AutoLoginController) AutoLogin() {
	defer p.Output("AutoLogin")

	akid := auth.GetAuthAppKeyService().GetAKId(p.AppKey)
	code, msg, respBody := login.GetLoginService().AutoLogin(p.UserId, akid)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
	if errorcode.EC_GL_SUCCESS == code {
		p.Resp["user_id"] = respBody.Userid
		p.Resp["access_token"] = respBody.AccessToken
		p.Resp["expire_second"] = respBody.ExpireSecond
		p.Resp["hx_account"] = respBody.HXAccount
		p.Resp["hx_passwd"] = respBody.HXPasswd
	}
}
